﻿Partial Public Class ValidateAccess

#Region "Public Properties"

    Public Property AuthicationPassed() As Boolean
        Get
            Return _authicationPassed
        End Get
        Set(ByVal Value As Boolean)
            _authicationPassed = Value
        End Set
    End Property

#End Region

#Region "UI Handlers"

    Private Sub btnOk_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnOk.Click
        GrantAccess()
    End Sub

    Private Sub txtPassword_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Input.KeyEventArgs) Handles txtPassword.KeyDown
        If e.Key = Key.Enter Then
            GrantAccess()
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnCancel.Click
        _authicationPassed = False
        Me.Close()
    End Sub

    Private Sub ValidateAccess_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Keyboard.Focus(txtPassword)
    End Sub
#End Region

#Region "Helper Methods"

    Private Sub GrantAccess()
        If String.Compare(txtPassword.Password, My.Settings.Password, False) = 0 Then
            _authicationPassed = True
            Me.Close()
        Else
            MessageBox.Show("Invalid password", "Error", MessageBoxButton.OK, MessageBoxImage.Error)
        End If
    End Sub
#End Region

#Region "Private Fields"

    Private _authicationPassed As Boolean = False

#End Region

End Class
